/**
 * 
 */
package xiaojian.toolkit.bean.tlv.test;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import xiaojian.toolkit.bean.tlv.decode.TLVDecodeContextFactory;
import xiaojian.toolkit.bean.tlv.decode.decoders.BeanTLVDecoder;


/**
 * @author hp
 *
 */
public class TlvDemo {

    public static void main(String[] args) {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
            	"xiaojian/toolkit/bean/tlv/test/tlvDemo.xml");
    	
    	byte[] bytes = new byte[]{
    			0, 0, 0, 2, 0, 0, 0, 12
    				,0, 0, 0, 100, 0, 0, 0, 4, 0, 0, 0, 1
    			,0, 0, 0, 2, 0, 0, 0, 12
    				,0, 0, 0, 100, 0, 0, 0, 4, 0, 0, 0, 2
    			,0, 0, 0, 2, 0, 0, 0, 24
					,0, 0, 0, 100, 0, 0, 0, 4, 0, 0, 0, 3
					,0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 121
    			,0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 100
    			,0, 0, 0, 2, 0, 0, 0, 12
    				,0, 0, 0, 100, 0, 0, 0, 4, 0, 0, 0, 4
    			,0, 0, 0, 2, 0, 0, 0, 12
    				,0, 0, 0, 100, 0, 0, 0, 4, 0, 0, 0, 5
    			,0, 0, 0, 2, 0, 0, 0, 12
					,0, 0, 0, 100, 0, 0, 0, 4, 0, 0, 0, 6
    			,0, 0, 0, 3, 0, 0, 0, 3, 65, 66, 67
    			};
    	
//    	DefaultTLVDecoderRepository decoderRepository = new DefaultTLVDecoderRepository();
//    	decoderRepository.add(byte[].class, new ByteArrayTLVDecoder());
//    	decoderRepository.add(int.class, new IntTLVDecoder());
//    	decoderRepository.add(Integer.class, new IntTLVDecoder());
//    	decoderRepository.add(byte.class, new ByteTLVDecoder());
//    	decoderRepository.add(Byte.class, new ByteTLVDecoder());
//    	decoderRepository.add(short.class, new ShortTLVDecoder());
//    	decoderRepository.add(Short.class, new ShortTLVDecoder());
//    	decoderRepository.add(long.class, new LongTLVDecoder());
//    	decoderRepository.add(Long.class, new LongTLVDecoder());
//    	decoderRepository.add(String.class, new StringTLVDecoder());
//    	
//    	DefaultContextBuilder ctxBuilder = new DefaultContextBuilder();
//    	ctxBuilder.setDecoderRepository(decoderRepository);
//    	ctxBuilder.setNumberCodec(DefaultNumberCodecs.getBigEndianNumberCodec());
//    	
//    	BeanTLVDecoder beanDecoder = new BeanTLVDecoder();
//    	beanDecoder.setCtxBuilder(ctxBuilder);
//    	
//    	decoderRepository.add(Object.class, beanDecoder);
//    	
    	BeanTLVDecoder beanDecoder = (BeanTLVDecoder)ctx.getBean("beanDecoder");
    	Object bean = beanDecoder.decode(bytes.length, bytes, 
    			beanDecoder.getDecodeContextFactory().createDecodeContext(SampleTLV.class, null));
    	System.out.println( bean );
    }
}
